package com.imooc.player;
/**
 * 播放列表管理类
 * @author Administrator
 *
 */

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class PlayListCollection {
	
	private Map<String,PlayList> playListMap;//播放列表集合
//	无参构造
	public PlayListCollection(){
		
	}
//	带参构造
	public PlayListCollection(Map<String, PlayList> playListMap) {
		super();
		this.setPlayListMap(playListMap);
	}
//	get和set方法
	public Map<String, PlayList> getPlayListMap() {
		return playListMap;
	}
	public void setPlayListMap(Map<String, PlayList> playListMap) {
		this.playListMap = playListMap;
	}
//	添加播放器列表
	public void addPlayList(PlayList playList){
		Scanner s = new Scanner(System.in);
		System.out.println("请输入播放列表名称：");
		String playListName=s.nextLine();
		playList.setPlayListName(playListName);
		System.out.println("创建成功！");
	}
//	删除播放列表
	public void deletPlayList(PlayList playList) {
		Scanner s = new Scanner(System.in);
		System.out.println("请输入要删除的播放列表名称：");
		String playListName=s.nextLine();
		if (playListMap.containsKey(playListName)) {
			playListMap.remove(playListName);
		}else{
			System.out.println("该播放列表不存在，请先将播放列表添加到播放器中~");
		}
		
		
	}
//	通过名字查询播放列表
	public PlayList searchPlayListByName(String playListName) {
		System.out.println("请输入要查询的播放列表名称：");
		Scanner s = new Scanner(System.in);
		String searchName=s.nextLine();
		if (playListMap.containsKey(searchName)) {
			System.out.println("该播放列表存在！");
			System.out.println("该播放列表的名称为"+searchName);
			System.out.println("该播放列表所有的歌曲为：");
			return playListMap.get(searchName);
		}else{
			System.out.println("该播放列表不存在！");
		}
		return null;
		
	}
	
//	显示所有播放列表名称
	public void displayAllPlayListName() {
		Iterator<Entry<String, PlayList>> it=playListMap.entrySet().iterator();
		while(it.hasNext()){
			
			System.out.println(it.next().getKey());
			System.out.println("播放列表所有歌曲为：");
			List<Song> songlist=it.next().getValue().getMusicList();
			for (int i=0;i<songlist.size();i++) {
				System.out.println(songlist.get(i));
			}
			
		}
	}
}
